from appium import webdriver
from appium.webdriver.common.appiumby import By
from time import sleep

desired_caps = {}
desired_caps['platformName'] = 'Android'  # 指定手机型号
desired_caps['platformVersion'] = '7'  # 手机Android的版本7.1.2
desired_caps['deviceName'] = '127.0.0.1:62001'  # 第一个连接的手机设备是62001
desired_caps['app'] = r'E:\apk\zuoyebang.apk'  # 指定要操作的软件或者包
desired_caps['appPackage'] = r'com.baidu.homework'
desired_caps['appActivity'] = r'com.baidu.homework.activity.init.InitActivity'
desired_caps['noReset'] = False  # False代表重新安装包或者软件，默认值False
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
driver.implicitly_wait(10)
sleep(3)
# 温馨提示
try:
    ele = driver.find_element(By.ID, 'com.baidu.homework:id/iknow_alert_dialog_button2')
except Exception as e:
    print('no agreebtn')
# # 跳过按钮
# try:
#     ele = driver.find_element(By.ID, 'com.baidu.homework:id/common_ui_titlebar_text_view_id')
# except Exception as e:
#     print('no skipbtn')
# # 登录/注册按钮
# try:
#     ele = driver.find_element(By.ID, 'com.baidu.homework:id/tv_login_register')
# except Exception as e:
#     print('no skipbtn')
